//
//  Shopping_Mall_ViewController.m
//  DA_V
//
//  Created by 中亿世联前台 on 15/4/21.
//  Copyright (c) 2015年 zhouhai. All rights reserved.
//

#import "Shopping_Mall_ViewController.h"
#import "CommodityListViewController.h"
#import "SearchViewController.h"
#import "CosmeticViewController.h"
#import "OneImageTableViewCell.h"
#import "NewScrollView.h"
#import "RoundBut.h"
#import "LoginViewController.h"
#import "MyDaV_ViewController.h"
#import "InfoViewController.h"
#import "InterFace.h"
#import "UIViewAdditions.h"
#import "AlertView.h"
#import "BindingViewController.h"
#import "ProductModel.h"
#import "SDWebImageManager.h"
#import "CategoryModel.h"
#import "AccountViewController.h"
#import "CommissionViewController.h"
#import "CommodityInFoViewController.h"
#import "ProductListModel.h"
#import "LoginData.h"
#import "GMDCircleLoader.h"
#import "CertificationViewController.h"

#import "InformationButton.h"

#import "NetStatus.h"
@interface Shopping_Mall_ViewController ()<NewScrollViewDelegate,UITextFieldDelegate,ProductModelDelegate,CategoryModelDelegate,LoginDelegate>
{

    AlertView *_loginAlerView;
    UIView *_loginAlertBackview;
    UITextField *nameTextField;
    UITextField *nameTextFiel1;
    
    UIView  *_alertBackview;
    AlertView *_alerView;
}
@property(nonatomic,retain) UIView *views;
@property(nonatomic,retain) UIView *alertView;

//－－－－－－推荐商品Model数组---------
@property(nonatomic,retain) NSMutableArray *productArr;

//----------商品类型数组-------------
@property(nonatomic,retain) NSMutableArray *categoryArr;



@end

@implementation Shopping_Mall_ViewController
@synthesize views,alertView;
- (void)viewDidLoad {
    [super viewDidLoad];
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.view.backgroundColor = LineColor;
    
    [GMDCircleLoader setOnView:self.view withTitle:@"加载中···" animated:YES];
    //------------------------------------
    self.productArr = [NSMutableArray array];
    self.categoryArr = [NSMutableArray array];
    
    //创建搜索框
    [self creatSearchBut];
    
    self.myTableView.backgroundColor = LineColor;
    
    
    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"shifouxianshi"]isEqualToString:@"0"]) {
        
    }else{
        //微信登陆提示框
        [self initUI];
    }
    
    
    //判断是否有网
    NetStatus *status = [[NetStatus alloc] init];
    if ([status.networkStatus isEqualToString:@"无网络"]) {
        [GMDCircleLoader hideFromView:self.view animated:YES];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"无网络" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }
    
    

//
//    //开始类型网络请求
    CategoryModel *categoryModel = [[CategoryModel alloc] init];
    categoryModel.categoryModelDelegate = self;
    [categoryModel getCategoryList:self.categoryArr];
    
    
//

   
}

- (void)getError{
[GMDCircleLoader hideFromView:self.view animated:YES];
}

#pragma mark - initUI
-(void)initUI{
   
    
    views = [[UIView alloc]init];
    views.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT+100);
    views.userInteractionEnabled = YES;
    views.backgroundColor = [UIColor blackColor];
    views.alpha = 0.4;
    [self.tabBarController.view addSubview:views];
    
    alertView = [[UIView alloc]initWithFrame:CGRectMake(50, SCREEN_HEIGHT/2-150, SCREEN_WIDTH-100, 170)];
    alertView.backgroundColor = [UIColor whiteColor];
    alertView.userInteractionEnabled = YES;
    alertView.layer.cornerRadius = 10;//设置那个圆角的有多圆
    [self.tabBarController.view addSubview:alertView];
    
    UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,  alertView.frame.size.width, 30)];
    topView.backgroundColor = [self colorWithHexString:@"#F5F5F5"];
    UIBezierPath *maskPath4 = [UIBezierPath bezierPathWithRoundedRect:topView.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer4 = [[CAShapeLayer alloc] init];
    maskLayer4.frame = topView.bounds;
    maskLayer4.path = maskPath4.CGPath;
    topView.layer.mask = maskLayer4;
    [alertView addSubview:topView];
    
    UILabel *topLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, topView.frame.size.width, 30)];
    topLabel.text = @"检测到您还未绑定微商账号";
    topLabel.textColor = [UIColor blackColor];
    topLabel.font = [UIFont systemFontOfSize:13];
    topLabel.textAlignment = NSTextAlignmentCenter;
    topLabel.backgroundColor = [UIColor clearColor];
    [topView addSubview:topLabel];

    //UIImage *image = [[UIImage imageNamed:@"xxx"] stretchableImageWithLeftCapWidth:10 topCapHeight:10];
    UIImageView *textBackView = [[UIImageView alloc]initWithImage:[[UIImage imageNamed:@"微信登陆后_03"]stretchableImageWithLeftCapWidth:10 topCapHeight:10]];
    textBackView.frame = CGRectMake(20, topView.bottom+10, 179, 30);
    textBackView.userInteractionEnabled = YES;
    [alertView addSubview:textBackView];
    
    
    nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, 0 , textBackView.frame.size.width-20 , 30)];
    nameTextField.tag = 1;
    //nameTextField.layer.borderWidth = 0.5;  // 给图层添加一个有色边框
    //nameTextField.layer.borderColor = [UIColor lightGrayColor].CGColor;
    nameTextField.placeholder = @"输入微商账号";
    nameTextField.font = [UIFont systemFontOfSize:15];
    //writePhoneNum.backgroundColor= [UIColor whiteColor];
    [textBackView addSubview:nameTextField];
    nameTextField.delegate = self;
    
    
    //
    //
    
    UIImageView *textBackView1 = [[UIImageView alloc]initWithImage:[[UIImage imageNamed:@"微信登陆后_03"]stretchableImageWithLeftCapWidth:10 topCapHeight:10]];
    textBackView1.frame = CGRectMake(20, textBackView.bottom+10, 179, 30);
    textBackView1.userInteractionEnabled = YES;
    [alertView addSubview:textBackView1];
    
    nameTextFiel1 = [[UITextField alloc] initWithFrame:CGRectMake(10, 0 , textBackView.frame.size.width-20 , 30)];
    nameTextFiel1.tag = 1;
    //nameTextField.layer.borderWidth = 0.5;  // 给图层添加一个有色边框
    //nameTextField.layer.borderColor = [UIColor lightGrayColor].CGColor;
    nameTextFiel1.placeholder = @"输入密码";
    nameTextFiel1.font = [UIFont systemFontOfSize:15];
    //writePhoneNum.backgroundColor= [UIColor whiteColor];
    [textBackView1 addSubview:nameTextFiel1];
    nameTextFiel1.delegate = self;

    
    UILabel *errorLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, textBackView1.bottom+5, topView.frame.size.width, 20)];
    errorLabel.text = @"您输入的信息有误，请重新输入";
    errorLabel.textColor = [self colorWithHexString:@"#EB2F6C"];
    errorLabel.font = [UIFont systemFontOfSize:13];
    errorLabel.textAlignment = NSTextAlignmentCenter;
    errorLabel.backgroundColor = [UIColor clearColor];
    errorLabel.hidden = YES;
    [alertView addSubview:errorLabel];

    
    [self createrOffLineUI:CGRectMake(0, textBackView1.bottom+31, alertView.frame.size.width, 0.5)];
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, textBackView1.bottom+32, alertView.frame.size.width/2, 28);
    //leftBtn.backgroundColor= [ UIColor whiteColor];
    UIBezierPath *maskPath1 = [UIBezierPath bezierPathWithRoundedRect:leftBtn.bounds byRoundingCorners:UIRectCornerBottomLeft cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init];
    maskLayer1.frame = leftBtn.bounds;
    maskLayer1.path = maskPath1.CGPath;
    leftBtn.layer.mask = maskLayer1;
    //[leftBtn addTarget:self action:@selector(clickLeft) forControlEvents:UIControlEventTouchUpInside];
    [leftBtn addTarget:self action:@selector(clickBang) forControlEvents:UIControlEventTouchUpInside];
    [leftBtn setImage:[UIImage imageNamed:@"weixindengluhou-02"] forState:UIControlStateNormal];
    [leftBtn setImage:[UIImage imageNamed:@"weixindengluhou-02"] forState:UIControlStateHighlighted];
    [alertView addSubview:leftBtn];
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(alertView.frame.size.width/2, leftBtn.top, alertView.frame.size.width/2, 28);
    UIBezierPath *maskPath11 = [UIBezierPath bezierPathWithRoundedRect:rightBtn.bounds byRoundingCorners:UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer11 = [[CAShapeLayer alloc] init];
    maskLayer11.frame = rightBtn.bounds;
    maskLayer11.path = maskPath11.CGPath;
    rightBtn.layer.mask = maskLayer11;
    [rightBtn addTarget:self action:@selector(cliclRight) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn setImage:[UIImage imageNamed:@"weixindengluhou-03"] forState:UIControlStateNormal];
    [rightBtn setImage:[UIImage imageNamed:@"weixindengluhou-03"] forState:UIControlStateHighlighted];
    [alertView addSubview:rightBtn];

    
   
}
#pragma -mark 获取推荐商品数据结束代理方法
- (void)getgetProductListEnd{
   [GMDCircleLoader hideFromView:self.view animated:YES];
    NSLog(@"商品数据==== %@",self.productArr);
      [self.myTableView reloadData];
}

#pragma -mark //获取推荐商品类型接口结束代理方法
- (void)getCategoryListEnd{
       [GMDCircleLoader hideFromView:self.view animated:YES];
    NSLog(@"商品类型数组==== %@",self.categoryArr);
    
    self.myTableView.tableHeaderView = [self createTableViewHead];
    
    [self.myTableView reloadData];
}

#pragma -mark //请求服务器繁华的错误信息代理
- (void)getrequesterror:(NSString *)error{
     [GMDCircleLoader hideFromView:self.view animated:YES];
    if ([error isEqualToString:@""]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"服务器异常,无法加载数据" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    } else{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:error delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
    }
}
#pragma -mark 网络异常代理／服务器起错误代理
- (void)requesterror{
     [GMDCircleLoader hideFromView:self.view animated:YES];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"网络异常,无法加载数据" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}
#pragma mark - UItextField delegate
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
#pragma -mark 创建提示框
- (void)createAlertView{
    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
    _loginAlertBackview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _loginAlertBackview.backgroundColor = [UIColor blackColor];
    _loginAlertBackview.alpha = 0.4;
    [window addSubview:_loginAlertBackview];
    
    
    _loginAlerView = [[[NSBundle mainBundle] loadNibNamed:@"Shopping_mall_xibs" owner:self options:nil] objectAtIndex:10];
    _loginAlerView.frame = CGRectMake(50, SCREEN_HEIGHT/2.0-130/2.0, SCREEN_WIDTH-100, 130);
    [_loginAlerView.confirmBut addTarget:self action:@selector(confirmButClick) forControlEvents:UIControlEventTouchUpInside];
    [_loginAlerView.cancelBut addTarget:self action:@selector(cancelButClick) forControlEvents:UIControlEventTouchUpInside];
    [window addSubview:_loginAlerView];
}
#pragma -mark 点击提示框去绑定银行卡事件
- (void)confirmButClick{
    [_loginAlerView removeFromSuperview];
    [_loginAlertBackview removeFromSuperview];
    self.hidesBottomBarWhenPushed = YES;
    BindingViewController *bindingVC = [[BindingViewController alloc] init];
    bindingVC.controller = self;
    [self.navigationController pushViewController:bindingVC animated:YES];
}

#pragma -mark 点击提示框稍后按钮
- (void)cancelButClick{
    [_loginAlerView removeFromSuperview];
    [_loginAlertBackview removeFromSuperview];
    
}

#pragma mark - clickBtn
-(void)clickLeft{
    [alertView removeFromSuperview];
    alertView = nil;
    [views removeFromSuperview];
    views =nil;
    
    views = [[UIView alloc]init];
    views.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT+100);
    views.userInteractionEnabled = YES;
    views.backgroundColor = [UIColor blackColor];
    views.alpha = 0.4;
    [self.tabBarController.view addSubview:views];
    
    alertView = [[UIView alloc]initWithFrame:CGRectMake(60, SCREEN_HEIGHT/2-150, SCREEN_WIDTH-120, 120)];
    alertView.backgroundColor = [UIColor whiteColor];
    alertView.userInteractionEnabled = YES;
    alertView.layer.cornerRadius = 10;//设置那个圆角的有多圆
    [self.tabBarController.view addSubview:alertView];
    
    
    
    UITextField *nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, 30 , alertView.frame.size.width-20-81 , 35)];
    nameTextField.tag = 1;
    nameTextField.layer.borderWidth = 0.5;  // 给图层添加一个有色边框
    nameTextField.layer.borderColor = [UIColor lightGrayColor].CGColor;
    nameTextField.placeholder = @"  验证码";
    nameTextField.font = [UIFont systemFontOfSize:15];
    //writePhoneNum.backgroundColor= [UIColor whiteColor];
    [alertView addSubview:nameTextField];
    nameTextField.delegate = self;
    
    UIButton *sendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    sendBtn.frame = CGRectMake(nameTextField.right, nameTextField.top, 81, 35);
    [sendBtn setBackgroundImage:[UIImage imageNamed:@"weixindengluhou-05"] forState:UIControlStateNormal];
    [sendBtn addTarget:self action:@selector(sendYan) forControlEvents:UIControlEventTouchUpInside];
    [alertView addSubview:sendBtn];
    
    
    [self createrOffLineUI:CGRectMake(0, nameTextField.bottom+39, alertView.frame.size.width, 0.5)];
  
    //验证码输入错误
    UILabel *alertLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, nameTextField.bottom, alertView.frame.size.width, 30)];
    alertLabel.text = @"验证码输入错误，请重新输入";
    alertLabel.numberOfLines = 0;
    alertLabel.font = [UIFont systemFontOfSize:14];
    alertLabel.textAlignment = NSTextAlignmentCenter;
    [alertView addSubview:alertLabel];
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, nameTextField.bottom+40, alertView.frame.size.width/2, 28);
    //leftBtn.backgroundColor= [ UIColor whiteColor];
    UIBezierPath *maskPath1 = [UIBezierPath bezierPathWithRoundedRect:leftBtn.bounds byRoundingCorners:UIRectCornerBottomLeft cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init];
    maskLayer1.frame = leftBtn.bounds;
    maskLayer1.path = maskPath1.CGPath;
    leftBtn.layer.mask = maskLayer1;
    [leftBtn addTarget:self action:@selector(clickBang) forControlEvents:UIControlEventTouchUpInside];
    [leftBtn setImage:[UIImage imageNamed:@"weixindengluhou-06"] forState:UIControlStateNormal];
    [leftBtn setImage:[UIImage imageNamed:@"weixindengluhou-06"] forState:UIControlStateHighlighted];
    [alertView addSubview:leftBtn];
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(alertView.frame.size.width/2, nameTextField.bottom+40, alertView.frame.size.width/2, 28);
    UIBezierPath *maskPath11 = [UIBezierPath bezierPathWithRoundedRect:rightBtn.bounds byRoundingCorners:UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer11 = [[CAShapeLayer alloc] init];
    maskLayer11.frame = rightBtn.bounds;
    maskLayer11.path = maskPath11.CGPath;
    rightBtn.layer.mask = maskLayer11;
    [rightBtn addTarget:self action:@selector(cliclRight) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn setImage:[UIImage imageNamed:@"weixindengluhou-03"] forState:UIControlStateNormal];
    [rightBtn setImage:[UIImage imageNamed:@"weixindengluhou-03"] forState:UIControlStateHighlighted];
    [alertView addSubview:rightBtn];


}
-(void)cliclRight{
    [alertView removeFromSuperview];
    alertView = nil;
    [views removeFromSuperview];
    views =nil;
    
    UIWindow *windown = [[[UIApplication sharedApplication] delegate] window];
    LoginViewController *loginVc = [[LoginViewController alloc] init];
    
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginVc];
    
    windown.rootViewController = nav;

    
}
#pragma mark - 立即绑定
-(void)clickBang{
    
    LoginData *data = [[LoginData alloc]init];
    data.delegate = self;
    [data bindwx:[[NSUserDefaults standardUserDefaults]objectForKey:@"openID"] andMobileNumber:nameTextField.text andLoginPass:nameTextFiel1.text];

}
#pragma mark - 绑定成功
-(void)bindwx:(NSDictionary *)sign{
    NSLog(@"%@",sign);
    if ([[sign objectForKey:@"status"] isEqualToString:@"success"]) {

    [[NSUserDefaults standardUserDefaults]setObject:[[sign objectForKey:@"data"] objectForKey:@"AgentID"] forKey:@"userID"];
    if ([[[sign objectForKey:@"data"] objectForKey:@"FatherAgent"] isEqual:[NSNull null]] || [[[sign objectForKey:@"data"] objectForKey:@"FatherLevelID"] isEqual:[NSNull null]] || [[[sign objectForKey:@"data"] objectForKey:@"FatherLevelName"] isEqual:[NSNull null]]){
        
    }else{
        [[NSUserDefaults standardUserDefaults]setObject:[[sign objectForKey:@"data"] objectForKey:@"FatherAgent"] forKey:@"FatherAgent"];
        [[NSUserDefaults standardUserDefaults]setObject:[[sign objectForKey:@"data"] objectForKey:@"FatherLevelID"] forKey:@"FatherLevelID"];
        [[NSUserDefaults standardUserDefaults]setObject:[[sign objectForKey:@"data"] objectForKey:@"FatherLevelName"] forKey:@"FatherLevelName"];
    }
    [[NSUserDefaults standardUserDefaults]setObject:[[sign objectForKey:@"data"] objectForKey:@"IsBindBankcard"] forKey:@"IsBindBankcard"];
    [[NSUserDefaults standardUserDefaults]setObject:[[sign objectForKey:@"data"] objectForKey:@"LevelID"] forKey:@"LevelID"];
    [[NSUserDefaults standardUserDefaults]setObject:[[sign objectForKey:@"data"] objectForKey:@"RealName"] forKey:@"RealName"];
    [[NSUserDefaults standardUserDefaults]setObject:[[sign objectForKey:@"data"] objectForKey:@"MobileNumber"] forKey:@"MobileNumber"];

    
    //成功
    [alertView removeFromSuperview];
    alertView = nil;
    [views removeFromSuperview];
    views =nil;
    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
    
    views = [[UIView alloc]init];
    views.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT+100);
    views.userInteractionEnabled = YES;
    views.backgroundColor = [UIColor blackColor];
    views.alpha = 0.4;
    [window addSubview:views];
    
    alertView = [[UIView alloc]initWithFrame:CGRectMake(50, SCREEN_HEIGHT/2-150, SCREEN_WIDTH-100, 120)];
    alertView.backgroundColor = [UIColor whiteColor];
    alertView.userInteractionEnabled = YES;
    alertView.layer.cornerRadius = 10;//设置那个圆角的有多圆
    [window addSubview:alertView];
    
    
    UIImageView *leftRightImage = [[UIImageView alloc]initWithFrame:CGRectMake(60, 40, 20, 22)];
    leftRightImage.image = [UIImage imageNamed:@"dingdanchong"];
    [alertView addSubview:leftRightImage];
    
    
    //验证码输入错误
    UILabel *alertLabel = [[UILabel alloc]initWithFrame:CGRectMake(leftRightImage.right, leftRightImage.top, 100, 22)];
    alertLabel.text = @"绑定成功";
    alertLabel.numberOfLines = 0;
    alertLabel.font = [UIFont systemFontOfSize:14];
    alertLabel.textAlignment = NSTextAlignmentLeft;
    [alertView addSubview:alertLabel];
    
    [self createrOffLineUI:CGRectMake(0, alertLabel.bottom+49-3, alertView.frame.size.width, 0.5)];
    
    
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, alertLabel.bottom+50-3, alertView.frame.size.width, 31);
    //leftBtn.backgroundColor= [ UIColor whiteColor];
    UIBezierPath *maskPath1 = [UIBezierPath bezierPathWithRoundedRect:leftBtn.bounds byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init];
    maskLayer1.frame = leftBtn.bounds;
    maskLayer1.path = maskPath1.CGPath;
    leftBtn.layer.mask = maskLayer1;
    [leftBtn addTarget:self action:@selector(clickTongGuo) forControlEvents:UIControlEventTouchUpInside];
    [leftBtn setImage:[UIImage imageNamed:@"weixindengluhou-07"] forState:UIControlStateNormal];
    [leftBtn setImage:[UIImage imageNamed:@"weixindengluhou-07"] forState:UIControlStateHighlighted];
    [alertView addSubview:leftBtn];
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[sign objectForKey:@"reason"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
    
}
#pragma mark - 微信登录回调失败
-(void)requistFail{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"网络异常,无法加载数据" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}
#pragma mark - 通过
-(void)clickTongGuo{
    [alertView removeFromSuperview];
    alertView = nil;
    [views removeFromSuperview];
    views =nil;
}
#pragma -mark 创建提示框
- (void)createAlertViewa{
    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
    _alertBackview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _alertBackview.backgroundColor = [UIColor blackColor];
    _alertBackview.alpha = 0.4;
    [window addSubview:_alertBackview];
    _alerView = [[[NSBundle mainBundle] loadNibNamed:@"Shopping_mall_xibs" owner:self options:nil] objectAtIndex:10];
    _alerView.frame = CGRectMake(50, SCREEN_HEIGHT/2.0-130/2.0, SCREEN_WIDTH-100, 130);
    [_alerView.confirmBut addTarget:self action:@selector(confirmButClicka) forControlEvents:UIControlEventTouchUpInside];
    [_alerView.cancelBut addTarget:self action:@selector(cancelButClicka) forControlEvents:UIControlEventTouchUpInside];
    [window addSubview:_alerView];
}
#pragma -mark 点击提示框稍后按钮
- (void)cancelButClicka{
    [_alertBackview removeFromSuperview];
    [_alerView removeFromSuperview];
    
}
#pragma -mark 点击提示框去绑定银行卡
- (void)confirmButClicka{
    [_alertBackview removeFromSuperview];
    [_alerView removeFromSuperview];
    //    BindingViewController *bindingVC = [[BindingViewController alloc] init];
    //    [self.navigationController pushViewController:bindingVC animated:YES];
    CertificationViewController *offline = [[CertificationViewController alloc]init];//绑定状态
    offline.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:offline animated:YES];
}
#pragma mark - 发送验证码
-(void)sendYan{
    NSLog(@"发送验证码");
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.hidesBottomBarWhenPushed = NO;
    self.navigationController.navigationBarHidden=NO;
    [self.productArr removeAllObjects];
     [GMDCircleLoader setOnView:self.view withTitle:@"加载中···" animated:YES];
    //    //开始推荐商品网络请求
    ProductModel *productModel = [[ProductModel alloc]init];
    productModel.productModelDelegate = self;
    [productModel getProductList:self.productArr];
}
#pragma -mark 创建搜索按钮
- (void)creatSearchBut{
    UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
//    but.backgroundColor = [UIColor orangeColor];
    [but setBackgroundImage:[UIImage imageNamed:@"首页_搜索"] forState:UIControlStateNormal];
    but.frame = CGRectMake(0, 20, self.view.frame.size.width - 100, self.navigationController.navigationBar.frame.size.height-15);
    [but addTarget:self action:@selector(searchButClick:) forControlEvents:UIControlEventTouchUpInside];
    
    InformationButton *infonmationBut = [[InformationButton alloc] initWithFrame:CGRectMake(0, 0, 23, 29)];
    infonmationBut.informationNum.text = @"20";
    [infonmationBut setImage:[UIImage imageNamed:@"查看库存_03"] forState:UIControlStateNormal];
    UIBarButtonItem *rightBut = [[UIBarButtonItem alloc] initWithCustomView:infonmationBut];
    [infonmationBut addTarget:self action:@selector(informationClick) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = rightBut;
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:but];
}

#pragma -mark 点击信封按钮事件
- (void)informationClick{
    
    InfoViewController *infomation =[[InfoViewController alloc] init];
    [self.navigationController pushViewController:infomation animated:YES];
}

#pragma -mark 点击搜索事件
- (IBAction)searchButClick:(id)sender {
    
    SearchViewController *searcVC = [[SearchViewController alloc]init];
    [self.navigationController pushViewController:searcVC animated:YES];
}



#pragma -mark 登录点击事件
- (IBAction)loginButClick:(id)sender {
//    LoginViewController *login = [[LoginViewController alloc]init];
//    login.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:login animated:YES];
    
    InfoViewController *info = [[InfoViewController alloc]init];
    info.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:info animated:YES];
}

#pragma -mark NewScrollView 的代理
- (void)getBut:(id)but{
    RoundBut *mybut = (RoundBut *)but;
    NSLog(@"点击事件tag == %zi",mybut.tag);
    CommodityListViewController *commList = [[CommodityListViewController alloc] init];
    commList.categoryModel = [self.categoryArr firstObject];
    commList.mytitle = mybut.titleLabel.text;
    
//    CosmeticViewController *cosmeticCV = [[CosmeticViewController alloc] init];
    
    AccountViewController *accountVC = [[AccountViewController alloc] init];
    
    CommissionViewController *commiss = [[CommissionViewController alloc] init];
//    if (mybut.tag == 1) {
//        [self.navigationController pushViewController:accountVC animated:YES];
//        return;
//    }
    NSString *bangDin = [[NSUserDefaults standardUserDefaults] objectForKey:@"IsBindBankcard"];
    bangDin = [NSString stringWithFormat:@"%@",bangDin];
    if (mybut.tag == 2) {
        if ([bangDin isEqualToString:@"0"]) {
            //未绑定
            [self createAlertViewa];
            return;
        }else{
        [self.navigationController pushViewController:commiss animated:YES];
        return;
        }
    }
    if (mybut.tag == 3) {
        if ([bangDin isEqualToString:@"0"]) {
            //未绑定
            [self createAlertViewa];
            return;
        }else{
            [self.navigationController pushViewController:accountVC animated:YES];
            return;
        }

        //跳到化妆品页面
       
    } else
        //跳到商品列表页面
    [self.navigationController pushViewController:commList animated:YES];
    
//    mybut.userInteractionEnabled = YES;
}

#pragma -mark 创建tableview 的HeadView
- (NewScrollView *)createTableViewHead{

    NewScrollView *myScrollView = [NewScrollView newScrollViewRoundButTitle:self.categoryArr frame:CGRectMake(0, 0, self.view.frame.size.width, 120)];
    myScrollView.backgroundColor = [UIColor whiteColor];
    myScrollView.mydelegate = self;
    //myScrollView.contentSize = CGSizeMake(self.view.frame.size.width *[self.categoryArr count]/2, 120);
    myScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, 120);

    return myScrollView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.productArr.count;
//    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 130;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *iden = @"shoppingCell";
    OneImageTableViewCell *cell =  [tableView dequeueReusableCellWithIdentifier:iden];
    if (cell == nil) {
        cell = (OneImageTableViewCell*)[[[NSBundle mainBundle] loadNibNamed:@"Shopping_mall_xibs" owner:self options:nil] objectAtIndex:8];
    }
 
//    NSArray *imagArr = @[@"首页--3b_12",@"首页--3b_13",@"首页--3b_14"];
//    cell.oneImage.image = [UIImage imageNamed:imagArr[indexPath.row]];
    ProductModel *productModel = self.productArr[indexPath.row];
    
    [cell showImageUrl:productModel.ThumbPath imageTitle:productModel.ProductName];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    ProductListModel *model1 = [[ProductListModel alloc] init];
//    model1.ProductID =@"1";
//    ProductListModel *model2 = [[ProductListModel alloc] init];
//    model2.ProductID =@"2";
//    ProductListModel *model3 = [[ProductListModel alloc] init];
//    model3.ProductID =@"3";
//    NSArray *arr = @[model1,model2,model3];
//    CommodityInFoViewController *comod = [[CommodityInFoViewController alloc] init];
//     comod.productlistModel = arr[indexPath.row];
//   comod.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:comod animated:YES];
    
    //------------------
    CommodityInFoViewController *comod = [[CommodityInFoViewController alloc] init];
    comod.productlistModel = self.productArr[indexPath.row];
    comod.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:comod animated:YES];
    //------------------
#warning -mark 首页暂时这样写
//    if (indexPath.row > 1) {
//        CommodityListViewController *commList = [[CommodityListViewController alloc] init];
//        commList.productModel = [self.productArr lastObject];
//        [self.navigationController pushViewController:commList animated:YES];
//        return;
//    }
//        CommodityListViewController *commList = [[CommodityListViewController alloc] init];
//        commList.productModel = self.productArr[indexPath.row];
//        [self.navigationController pushViewController:commList animated:YES];
    
}
-(void)createrOffLineUI:(CGRect)rect{
    UIView *lines = [[UIView alloc] initWithFrame:rect];
    lines.backgroundColor = [UIColor colorWithRed:179/255.0 green:179/255.0 blue:179/255.0 alpha:1];
    [alertView addSubview:lines];
}
//传入字符串返回RGB
- (UIColor *) colorWithHexString: (NSString *)color
{
    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    // String should be 6 or 8 characters
    if ([cString length] < 6) {
        return [UIColor clearColor];
    }
    
    // strip 0X if it appears
    if ([cString hasPrefix:@"0X"])
        cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"])
        cString = [cString substringFromIndex:1];
    if ([cString length] != 6)
        return [UIColor clearColor];
    
    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;
    
    //r
    NSString *rString = [cString substringWithRange:range];
    
    //g
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    
    //b
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];
    
}

@end
